<template>
    <div id="sidebar">
        <el-menu
            default-active="/System/StudentsList"
            class="el-menu-vertical-demo"
            :router="true"
        >
            <el-submenu
                v-for="item in sideBarList.list"
                :index="item.index"
                :key="item.index"
            >
                <template slot="title">
                    <i :class="item.icon"></i>
                    <span>{{ item.title }}</span>
                </template>
                <el-menu-item
                    v-for="sub in item.subMenu"
                    :index="sub.index"
                    :key="sub.index"
                    >{{ sub.title }}
                </el-menu-item>
            </el-submenu>
        </el-menu>
    </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers("login");
export default {
    data() {
        return {
            isAdmin: "", //false  切换动态列表
        };
    },

    created() {
        // // 动态菜单基于此代码实现--start
        const Admin = JSON.parse(localStorage.getItem("loginUser"));

        this.isAdmin = Admin.isAdmin;

        // // 动态菜单基于此代码实现--end
        //阿大撒大撒
    },
    computed: {
        ...mapState(["user"]),
        sideBarList() {
            if (this.isAdmin) {
                return {
                    list: [
                        {
                            title: "管理员管理",
                            index: "1",
                            icon: "el-icon-user",
                            subMenu: [
                                {
                                    title: "查看管理员",
                                    index: "/System/AdminsList",
                                },
                                {
                                    title: "新增管理员",
                                    index: "/System/AdminsAdd",
                                },
                                {
                                    title: "理赔审核",
                                    index: "/System/AdminsCheck",
                                },
                            ],
                        },
                        {
                            title: "销售员管理",
                            index: "2",
                            icon: "el-icon-school",
                            subMenu: [
                                {
                                    title: "查看销售员",
                                    index: "/System/salespersonsList",
                                },
                            ],
                        },
                        {
                            title: "保险分类管理",
                            index: "3",
                            icon: "el-icon-s-custom",
                            subMenu: [
                                {
                                    title: "查看保险分类",
                                    index: "/System/Types",
                                },
                            ],
                        },
                        {
                            title: "保险产品管理",
                            index: "4",
                            icon: "el-icon-s-custom",
                            subMenu: [
                                {
                                    title: "查看保险产品",
                                    index: "/System/GetInsuresList",
                                },
                            ],
                        },
                        {
                            title: "保险订单管理",
                            index: "5",
                            icon: "el-icon-s-custom",
                            subMenu: [
                                {
                                    title: "查看订单信息",
                                    index: "/System/OrdersList",
                                },
                            ],
                        },
                        {
                            title: "退保申请管理",
                            index: "6",
                            icon: "el-icon-s-custom",
                            subMenu: [
                                {
                                    title: "处理退保申请",
                                    index: "/System/SurrenderList",
                                },
                            ],
                        },
                        {
                            title: "客户管理",
                            index: "7",
                            icon: "el-icon-s-custom",
                            subMenu: [
                                {
                                    title: "查看客户",
                                    index: "/System/CustomerList",
                                },
                            ],
                        },
                    ],
                };
            } else {
                return {
                    list: [
                        {
                            title: "保险订单管理",
                            index: "1",
                            icon: "el-icon-user",
                            subMenu: [
                                {
                                    title: "保险订单列表",
                                    index: "/System/SaleManOrder",
                                },
                            ],
                        },
                        {
                            title: "客户管理",
                            index: "2",
                            icon: "el-icon-school",
                            subMenu: [
                                {
                                    title: "我的客户",
                                    index: "/System/MyCustomerList",
                                },
                            ],
                        },
                        {
                            title: "理赔管理",
                            index: "3",
                            icon: "el-icon-s-custom",
                            subMenu: [
                                {
                                    title: "理赔列表",
                                    index: "/System/MyClaimsList",
                                },
                                {
                                    title: "新增理赔",
                                    index: "/System/SubmitClaimMsg",
                                },
                            ],
                        },
                    ],
                };
            }
        },
    },
};
</script>

<style>
</style>